<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>学生登录</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../css/layui.css" media="all">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>

	<body>

		<div id="app">
			<div class="layui-container">
				<div class="layui-row ">
					<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
						<legend>学生登录</legend>
					</fieldset>

					<div class="layui-col-md-offset3" style="margin-top: 100px;">
						<form class="layui-form" action="">

							<div class="layui-form-item ">

								<label class="layui-form-label"><i class="layui-icon layui-icon-username" ></i>  </label>
								<div class="layui-input-inline">
									<input type="text" name="stuNum" v-model="stuNum" lay-verify="title" autocomplete="off" placeholder="请输入学号" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label"><i class="layui-icon layui-icon-password" ></i></label>
								<div class="layui-input-inline">
									<input type="password" name="stuPwd" v-model="stuPwd" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label"><i class="layui-icon layui-icon-vercode" ></i></label>
								<div class="layui-input-inline">
									<input type="text" name="kaptcha" v-model="kaptcha" lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">

								</div>
								<div style="margin-left: 0px;">
									<img src="http://localhost:8080/kaptcha.jpg" id="kaptchaImage" @click="reloadCode" title="点击刷新验证码"/>
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-input-block">
									<!--lay-submit="" lay-filter="demo1"-->
									<button type="button" class="layui-btn" @click="stuLogin()">立即提交</button>
									<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>

			<div class="layui-container">
				<div class="layui-fluid">

				</div>
			</div>
		</div>
		<script src="../layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/jquery.cookie.js"></script>
		<script src="http://cdn.bootcss.com/blueimp-md5/1.1.0/js/md5.min.js"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
		<script>
			
			if(window!=top){
				top.location.href=window.location.href;
			}
			
			//目前存在用来做相关测试
			$(function() {

				$(document).bind("contextmenu", function(e) {
					return false;
				});

				var vue = new Vue({
					"el": "#app",
					"data": {
						stuNum: "",
						stuPwd: "",
						kaptcha: ""
					},
					"methods": {
						"stuLogin": function() {
							//alert("@@成功" + this.stuNum + ":" + this.stuPwd + ":" + this.icode);
							var stuNum = this.stuNum;
							var stuPwd = md5(this.stuPwd);
							var kaptcha = this.kaptcha;
							$.ajax({
								xhrFields: {
									withCredentials: true
								},
								type: "post",
								url: "http://localhost:8080/student/studentLogin.do",
								async: false,
								dataType: "json",
								data: {
									//message: JSON.stringify(data.field)
									stuNum: stuNum,
									stuPwd: stuPwd,
									kaptcha: kaptcha
								},
								success: function(data) {
									//alert("数据：" + data);
									if(data == "no") {
										alert("用户名或密码错误！");
										window.location.href = "stulogin.html";
									} else if(data == "error") {
										alert("验证码输入错误");
										vue.reloadCode();

									} else {
										$.cookie("sid", data, {
											expires: 7,
											path: '/'
										});
										window.location.href = "stuindex.html";
									}

								},
								error: function(data) {
									alert("失败");

								}
							});
						},
						"reloadCode": function() {
							var time = new Date().getTime();
							document.getElementById("kaptchaImage").src = "http://localhost:8080/kaptcha.jpg?" + time;
						}
					}

				})
			})

			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;

				//日期
				laydate.render({
					elem: '#date'
				});
				laydate.render({
					elem: '#date1'
				});

				//创建一个编辑器
				var editIndex = layedit.build('LAY_demo_editor');

				//自定义验证规则
				form.verify({
					title: function(value) {
						if(value.length != 12) {
							return '学号不正确';
						}
					},
					pass: [/(.+){6,20}$/, '密码必须6到20位'],
					content: function(value) {
						layedit.sync(editIndex);
					}
				});

				//监听指定开关
				form.on('switch(switchTest)', function(data) {
					layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
						offset: '6px'
					});
					layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
				});

			});
		</script>

	</body>

</html>